﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common.Utility
{
    public class ParamWhere
    {
        //List<ParamWhere> listParamWhere = new List<ParamWhere>();
        public WhereState whereState { get; set; }
        public string Column { get; set; }
        public Param Pars { get; set; }
       
        public ParamWhere(string column, WhereState whereState, Param pars)
        {
            this.Column = column;
            this.whereState = whereState;
            this.Pars = pars;
        }

        public string GetWhereStr()
        {
            switch (this.whereState)
            {
                case WhereState.eq: return eq();
                case WhereState.gt: return gt();
                case WhereState.lt: return lt();
                case WhereState.like: return like();
                case WhereState.include: return include();
                default:
                    return "";
            }
        }

        public string eq()
        {
            return string.Format("{0} ={1}", this.Column, this.Pars.SqlParam);
        }

        public string gt()
        {
            return string.Format("{0} >{1}", this.Column, this.Pars.SqlParam);
        }

        private string lt()
        {
            return string.Format("{0} <{1}", this.Column, this.Pars.SqlParam);
        }

        public string like()
        {
            return string.Format("{0} like %{1}%", this.Column, this.Pars.SqlParam);
        }
        public string include()
        {
            return string.Format("{0} in ({1})", this.Column, this.Pars.ValueParam);
        }
    }

    public enum WhereState
    {
        /// <summary>
        /// 等于
        /// </summary>
        eq,
        /// <summary>
        ///  大于
        /// </summary>
        gt,
        /// <summary>
        /// 小于
        /// </summary>
        lt,
        /// <summary>
        /// like '%%'
        /// </summary>
        like,
        /// <summary>
        ///  in()
        /// </summary>
        include

    }
}
